home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / GAS_1_38.ARJ / BIGNMCPY.C < prev    next >
C/C++ Source or Header  |  1989-03-01  |  2KB  |  76 lines

  1. /* bignum_copy.c - copy a bignum
  2.    Copyright (C) 1987 Free Software Foundation, Inc.
  3.  
  4. This file is part of GAS, the GNU Assembler.
  5.  
  6. GAS is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GAS is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GAS; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "bignum.h"
  21.  
  22. #ifdef USG
  23. #define bzero(s,n) memset(s,0,n)
  24. #define bcopy(from,to,n) memcpy(to,from,n)
  25. #endif
  26.  
  27. /*
  28.  *            bignum_copy ()
  29.  *
  30.  * Copy a bignum from in to out.
  31.  * If the output is shorter than the input, copy lower-order littlenums.
  32.  * Return 0 or the number of significant littlenums dropped.
  33.  * Assumes littlenum arrays are densely packed: no unused chars between
  34.  * the littlenums. Uses bcopy() to move littlenums, and wants to
  35.  * know length (in chars) of the input bignum.
  36.  */
  37.  
  38. /* void */
  39. int
  40. bignum_copy (in, in_length, out, out_length)
  41.      register LITTLENUM_TYPE *    in;
  42.      register int        in_length; /* in sizeof(littlenum)s */
  43.      register LITTLENUM_TYPE *    out;
  44.      register int        out_length; /* in sizeof(littlenum)s */
  45. {
  46.   register int    significant_littlenums_dropped;
  47.  
  48.   if (out_length < in_length)
  49.     {
  50.       register LITTLENUM_TYPE *    p; /* -> most significant (non-zero) input littlenum. */
  51.  
  52.       bcopy ((char *)in, (char *)out, out_length << LITTLENUM_SHIFT);
  53.       for (p = in + in_length - 1;   p >= in;   -- p)
  54.     {
  55.       if (* p) break;
  56.     }
  57.       significant_littlenums_dropped = p - in - in_length + 1;
  58.       if (significant_littlenums_dropped < 0)
  59.     {
  60.       significant_littlenums_dropped = 0;
  61.     }
  62.     }
  63.   else
  64.     {
  65.       bcopy ((char *)in, (char *)out, in_length << LITTLENUM_SHIFT);
  66.       if (out_length > in_length)
  67.     {
  68.       bzero ((char *)(out + out_length), (out_length - in_length) << LITTLENUM_SHIFT);
  69.     }
  70.       significant_littlenums_dropped = 0;
  71.     }
  72.   return (significant_littlenums_dropped);
  73. }
  74.  
  75. /* end: bignum_copy.c */
  76.